//导入
let {src,dest,watch} = require('gulp'),
    sass = require('gulp-sass'),
    cssnano = require('gulp-cssnano'),
    rename = require('gulp-rename'),
    htmlmin = require('gulp-htmlmin'),
    uglify = require('gulp-uglify'),
    babel = require('gulp-babel'),
    concat = require('gulp-concat'),
    imagemin = require('gulp-imagemin');

    //首页
    function fnCopyIndex(){
        return src('./src/index.html')
        .pipe(dest('./dist'));
    }
    //css
    function fnCss(){
        return src('./src/sass/*.scss')
        .pipe(sass({outputStyle: 'expanded'}))
        .pipe(rename({suffix : '.min'}))
        .pipe(dest('./dist/css'));
    }
    //js
    function fnJs(){
        return src('./src/js/*.js')
        .pipe(babel({
            presets: ['@babel/env']
        }))
        .pipe(uglify())
        .pipe(rename({suffix : '.min'}))
        .pipe(dest('./dist/page'));
    }
    //html
    function fnPage(){
        return src('./src/page/*.html')
        .pipe(htmlmin())
        .pipe(dest('./dist/page'));
    }
    //img
    function fnImg(){
        return src('./src/img/*')
        .pipe(imagemin())
        .pipe(dest('./dist/img'));
    }
    //watch
    function fnWatch(){
        watch('./src/index.html',fnCopyIndex);
        watch('./src/img/*',fnImg);
        watch('./src/page/*html',fnPage);
        watch('./src/js/*.js',fnJs);
        watch('./src/sass/*.scss',fnCss);

    }

    //导出
    exports.copyIndex = fnCopyIndex;
    exports.css = fnCss;
    exports.js = fnJs;
    exports.html = fnPage;
    exports.img = fnImg;
    exports.default = fnWatch;
